package com.ruoyi.paint.admin.utils;

import com.ruoyi.common.exception.ServiceException;
import net.sourceforge.pinyin4j.PinyinHelper;

public class PinyinUtil {

    public static String getFirstLetter(String chinese) {
        StringBuilder pybf = new StringBuilder();
        char[] arr = chinese.toCharArray();
        for (char c : arr) {
            try {
                String[] temp = PinyinHelper.toHanyuPinyinStringArray(c);
                if (temp != null && temp.length > 0) {
                    pybf.append(temp[0].charAt(0));
                }
            } catch (ServiceException e) {
                e.printStackTrace();
            }
        }
        return pybf.toString().toUpperCase();
    }
}
